// 路由配置相关的内容
import Vue from 'vue';
import VueRouter from 'vue-router';
// 使用
Vue.use(VueRouter);
// 引入组件
import HomePage from '@/views/HomePage/HomePage';
import CategoryPage from '@/views/CategoryPage/CategoryPage';
import FindPage from '@/views/FindPage/FindPage';
import CartPage from '@/views/CartPage/CartPage';
import MinePage from '@/views/MinePage/MinePage';

// 路由规则的配置
// 首次进入页面就加载
var routes = [{
    path: '/',
    redirect: '/homepage'
},
    {
    path: '/homepage',
    component: HomePage,
    meta: { showTabBar: true },
    },
    {
    path: '/categorypage',
    component: CategoryPage,
    meta: { showTabBar: true },
}, {
    path: '/findpage',
    component: FindPage,
    meta: { showTabBar: true },
}, {
    path: '/cartpage',
    component: CartPage,
    meta: { showTabBar: true },
}, {
    path: '/minepage',
    component: MinePage,
    meta: { showTabBar: true },
}, {
    path: '/loginpage',
    // 路由元信息-设置字段判定需求
    meta: { showTabBar: false },
    // 路由懒加载--按需引入--首屏加载慢
    component: () =>
        import ('../views/LoginPage/LoginPage.vue')
}, {
    path: '/searchpage',
    // 路由元信息-设置字段判定需求
    meta: { showTabBar: true },
    // 路由懒加载--按需引入--首屏加载慢
    component: () =>
        import ('../views/SearchPage/SearchPage.vue')
}, {
    path: '/goodslist',
    // 路由元信息-设置字段判定需求
    meta: { showTabBar: false },
    // 路由懒加载--按需引入--首屏加载慢
    component: () =>
        import ('../views/GoodsList/GoodsList.vue')
}, {
    path: '/goodsdetails',
    // 路由元信息-设置字段判定需求
    meta: { showTabBar: false },
    // 路由懒加载--按需引入--首屏加载慢
    component: () =>
        import ('../views/GoodsDetails/GoodsDetais.vue')
}];

// 生成路由对象--创建router实例
var router = new VueRouter({
    routes,
    scrollBehavior(to, from, saveTop) {
        // console.log(to);
        // console.log(from);
        // console.log(saveTop);
        if (saveTop) {
            return saveTop
        } else {
            return { x: 0, y: 0 }
        }
    }
});

export default router;